package com.ruoyi.customer.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.customer.domain.bo.TCommentRecordBo;
import com.ruoyi.customer.domain.vo.TCommentRecordVo;
import com.ruoyi.customer.service.ITCommentRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 点评信息记录
 *
 * @author ruoyi
 * @date 2023-10-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/customer/commentRecord")
public class TCommentRecordController extends BaseController {

    private final ITCommentRecordService iTCommentRecordService;

    /**
     * 查询点评信息记录列表
     */
    //@SaCheckPermission("customer:commentRecord:list")
    @GetMapping("/list")
    public TableDataInfo<TCommentRecordVo> list(TCommentRecordBo bo, PageQuery pageQuery) {
        return iTCommentRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出点评信息记录列表
     */
    //@SaCheckPermission("customer:commentRecord:export")
    @Log(title = "点评信息记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TCommentRecordBo bo, HttpServletResponse response) {
        List<TCommentRecordVo> list = iTCommentRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "点评信息记录", TCommentRecordVo.class, response);
    }


    /**
     * 导出点评信息记录列表
     */
    //@SaCheckPermission("customer:commentRecord:export")
    @Log(title = "点评信息记录")
    @GetMapping("/noList")
    public R<List<TCommentRecordVo>> noList(TCommentRecordBo bo) {
        return R.ok(iTCommentRecordService.queryList(bo));
    }

    /**
     * 获取点评信息记录详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("customer:commentRecord:query")
    @GetMapping("/{id}")
    public R<TCommentRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iTCommentRecordService.queryById(id));
    }

    /**
     * 新增点评信息记录
     */
    //@SaCheckPermission("customer:commentRecord:add")
    @Log(title = "点评信息记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TCommentRecordBo bo) {
        return toAjax(iTCommentRecordService.insertByBo(bo));
    }

    /**
     * 修改点评信息记录
     */
    //@SaCheckPermission("customer:commentRecord:edit")
    @Log(title = "点评信息记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TCommentRecordBo bo) {
        return toAjax(iTCommentRecordService.updateByBo(bo));
    }

    /**
     * 删除点评信息记录
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("customer:commentRecord:remove")
    @Log(title = "点评信息记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iTCommentRecordService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
